package com.itheima.hw.test2;

import java.util.Collections;
import java.util.concurrent.*;

public class Test {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        MyRunnable r = new MyRunnable();

        //1.创建线程池对象
        ExecutorService pool = new ThreadPoolExecutor(
                2,
                5,
                1000,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );

        //2.执行两个任务
        Future<?> f1 = pool.submit(r);
        Future<?> f2 = pool.submit(r);


        System.out.println("==========================");
        f1.get();
        f2.get();


        System.out.println(r.one+",max="+ Collections.max(r.one));
        System.out.println(r.two+",max="+ Collections.max(r.two));

        if (r.one.stream().max(Integer::compareTo).get() > r.two.stream().max(Integer::compareTo).get()) {
            System.out.println("小明中奖了:"+Collections.max(r.one));
        }else{
            System.out.println("小红中奖了:"+Collections.max(r.two));
        }


    }
}
